package com.geostar.constructionland.common.entity.aly;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;

/**
 * @author yelll
 * @since 2020-6-3 10:46
 **/
public class AdjustResponse<T> implements Serializable {
    private int status;
    private String message;
    private T data;
    public AdjustResponse(){

    }
    private AdjustResponse(int status) {
        this.status = status;
    }

    public AdjustResponse(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public AdjustResponse(int status, T data) {
        this.status = status;
        this.data = data;
    }

    private AdjustResponse(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;

    }

    @JsonIgnore
    public boolean isSuccess() {
        return this.status == AlyCode.SUCCESS.getCode();
    }

    public int getStatus() {
        return status;
    }

    public T getData() {
        return data;
    }

    public String getMessage() {
        return message;
    }

    public static <T> AdjustResponse<T> createBySuccess() {
        return new AdjustResponse<T>(AlyCode.SUCCESS.getCode(), AlyCode.SUCCESS.getDesc());
    }

    public static <T> AdjustResponse<T> createBySuccessMessage(String message) {
        return new AdjustResponse<T>(AlyCode.SUCCESS.getCode(), message);
    }

    public static <T> AdjustResponse<T> createBySuccess(T data) {
        return new AdjustResponse<T>(AlyCode.SUCCESS.getCode(), AlyCode.SUCCESS.getDesc(), data);
    }

    public static <T> AdjustResponse<T> createBySuccess(String message, T data) {
        return new AdjustResponse<T>(AlyCode.SUCCESS.getCode(), message, data);
    }

    public static <T> AdjustResponse<T> createByError() {
        return new AdjustResponse<T>(AlyCode.ERROR.getCode(), AlyCode.ERROR.getDesc());
    }

    public static <T> AdjustResponse<T> createByErrorMessage(String errorMessage) {
        return new AdjustResponse<T>(AlyCode.ERROR.getCode(), errorMessage);
    }

    public static <T> AdjustResponse<T> createByErrorCodeMessage(int errorCode, String errorMessage) {
        return new AdjustResponse<T>(errorCode, errorMessage);
    }
}
